/**
 * LaptopConfigurator.java
 *
 *
 *
 * @author Andrew Shore
 * @version
 */

import javax.swing.JOptionPane;

public class SimpleCalculator {

	/**
	 * class level constants
	 */
	public static final String MENU = 
		"Enter \"add int\" to add integer values\n" +
		"Enter \"subtract int\" to subtract integer values\n" +
		"Enter \"subtract double\" to subtract double values\n" +
		"Enter \"square int\" to square an integer value\n" +
		"Enter \"square double\" to square a double value\n" +
		"Enter \"area of square\" to determine area of a square\n" +
		"Enter \"area of circle\" to determine area of a circle\n" +
		"Enter \"exit\" to quit the program\n";
	
	public static final String ADD_INT="add int";
	public static final String SUBTRACT_INT = "subtract int";
	public static final String SUBTRACT_DOUBLE= "subtract double";
	public static final String SQUARE_INT="square int";
	public static final String SQUARE_DOUBLE="square double";
	public static final String AREA_OF_SQUARE="area of square";
	public static final String AREA_OF_CIRCLE="area of circle";
	public static final String QUIT = "exit";
	
	public static final double PI=3.14;
	

	
	
	
	
	
	/**
	 * This method is complete
	 */
	public static void showGreeting() {
		JOptionPane.showMessageDialog(null, 
				"Welcome to the CSCE145 Simple Calculator!");
	}

	/**
	 * You must finish the implementation of this method
	 */
	public static String showMenu() {
		String response = "";
		response=JOptionPane.showInputDialog(null, MENU);
		

		return response;
	}
	public static void showMessage(String message)	{
		JOptionPane.showMessageDialog(null, message);
	}

	/**
	 * You must finish the implementation of this method
	 */
	public static int promptForInteger(String prompt) {
		int value = 0;
		
		String answer=JOptionPane.showInputDialog(null, prompt );
		
		value=Integer.parseInt(answer);


		return value;
	}

	/**
	 * You must finish the implementation of this method
	 */
	public static double promptForDouble(String prompt) {
		double value = 0.0;

		String answer=JOptionPane.showInputDialog(null, prompt);
		value=Double.parseDouble(answer);
		

		return value;
	}
	
	/**
	 * This method is complete
	 */
	public static int subtractInt(int a, int b) {
		int answer = 0;

		answer = a - b;

		return answer;
	}

	//add the other methods indicated by the UML class diagram
	public static int addInt(int a, int b)	{
		int answer=0;
		answer=a+b;
		return answer;
	}
	
	public static int squareInt(int a){
		int answer=0;
		answer=a*a;
		return answer;
	}
	
	public static int areaOfRectangle(int width, int length) {
		int area=0;
		area=length*width;
		return area;
	}
	
	public static double addDouble(double a, double b) {
		double answer=0;
		answer=a+b;
		return answer;
	}
	
	public static double subtractDouble(double a, double b)	{
		double answer=0;
		answer=a-b;
		return answer;
	}
	
	public static double squareDouble(double a) {
		double answer=0;
		answer=a*a;
		return answer;
	}
	
	public static double areaOfCircle(int radius) {
		double area=0;
		area=PI*radius*radius;
		return area;
	}
	
	
	
	
	
	
	
	
	/**
	 * the main algorithm is basically implemented, add code where
	 * indicated
	 */
	public static void main(String[] args) {
		
		//declare variables
		String response = "";
		
		/**
		 * generic variables that can be used 
		 * where needed.
		 */
		int iValue01 = 0; 
		int iValue02 = 0;
		int iAnswer = 0;
		double dValue01 = 0.0;
		double dValue02 = 0.0;
		double dAnswer = 0.0;

		
		//1. Display greeting to user
		SimpleCalculator.showGreeting();

		//2. start loop
		do {

			response = SimpleCalculator.showMenu();

			//user indicates that they wish to subtract int values
			if (response.equalsIgnoreCase(SUBTRACT_INT)) {
				
				// prompt the user for the first integer value
				iValue01 = SimpleCalculator.promptForInteger("Please enter the value to subtract from:");
				
				// prompt the user for the second integer value
				iValue02 = SimpleCalculator.promptForInteger("Please enter the value to subtract:");
				
				// call the subtract method and assign the return value 
				// to a local variable
				iAnswer = SimpleCalculator.subtractInt(iValue01, iValue02);
				
				// use showMessage to display the answer in a descriptive message
			
				SimpleCalculator.showMessage(iValue01 + " - " + iValue02 + " = " + iAnswer);
			} 
			// user indicates that they wish to subtract double values
			else if (response.equalsIgnoreCase(SUBTRACT_DOUBLE)) {
				// prompt the user for the first double value
				dValue01=SimpleCalculator.promptForDouble("Please enter the value to subtract from:");
				
				// prompt the user for the second double value
				dValue02=SimpleCalculator.promptForDouble("Please enter the value to subtract:");
				// call the subtract method and assign the return value 
				dAnswer=SimpleCalculator.subtractDouble(dValue01, dValue02);
				// to a local variable

				// use showMessage to display the answer in a descriptive message
				SimpleCalculator.showMessage(dValue01 + "-" + dValue02 + "=" + dAnswer);
			}
			//add other possible responses here
			else if(response.equalsIgnoreCase(ADD_INT)){
				iValue01=SimpleCalculator.promptForInteger("Please enter the value to be added to:");
				
				iValue02=SimpleCalculator.promptForInteger("Please enter the value to add:");
				
				iAnswer=SimpleCalculator.addInt(iValue01, iValue02);
				SimpleCalculator.showMessage(iValue01+ "+" +iValue02+ "="+ iAnswer);
			}
			else if(response.equalsIgnoreCase(SQUARE_INT)){
				iValue01=SimpleCalculator.promptForInteger("Please enter the integer to be squared:");
				iAnswer=SimpleCalculator.squareInt(iValue01);
				SimpleCalculator.showMessage(iValue01+ " squared="+ iAnswer);
			}
			else if(response.equalsIgnoreCase(SQUARE_DOUBLE)){
				dValue01=SimpleCalculator.promptForDouble("Please enter the double value to be squared:");
				dAnswer=SimpleCalculator.squareDouble(dValue01);
				SimpleCalculator.showMessage(dValue01+ " squared="+ dAnswer);			
				}
			else if(response.equalsIgnoreCase(AREA_OF_SQUARE)){
				iValue01=SimpleCalculator.promptForInteger("Please enter the width:");
				iValue01=SimpleCalculator.promptForInteger("Please enter the lenth:");
				iAnswer=SimpleCalculator.areaOfRectangle(iValue01, iValue02);
				SimpleCalculator.showMessage("The area of an object with width "+iValue01+" and length "+ iValue02+" is "+iAnswer );
			}
			else if(response.equalsIgnoreCase(AREA_OF_CIRCLE)){
				iValue01=SimpleCalculator.promptForInteger("Please enter the radius of the circle:");
				dAnswer=SimpleCalculator.areaOfCircle(iValue01);
				SimpleCalculator.showMessage("The area of a circle with radius "+iValue01+" is "+dAnswer);
			}
			else if(response.equalsIgnoreCase(QUIT)){
				// show closing message
				JOptionPane.showMessageDialog(null, "Thank you for using the simple calculator program, Goodbye.");
				
				break;// exits the loop
			}
			else {
				JOptionPane.showMessageDialog(null, "Error, response not valid. Please try again or type exit to quit");
				// user didn't enter a valid response show error message

			}

		}while(true);// be very careful with infinite loops

		
		

	}

} // LaptopConfigurator

